# -*- coding: utf-8 -*-
"""
@Time : 2024/4/19 18:40
@Author : ChenXiaoliang
@Email : middlegod@sina.com
@File : get_hot_comments.py
"""
import requests

from utils import get_params
from get_song_id import search_song_id
from get_song_lyric import get_lyric

song_name = input("请输入歌曲名：")
song_id = search_song_id(song_name)
# 返回的是数字类型，转成字符串类型
song_id = str(song_id)
print("查找到的歌曲id：",song_id)
if song_id:
    url = "https://music.163.com/weapi/comment/resource/comments/get?csrf_token="
    params = get_params(song_id)
    data = {"params":params[0],"encSecKey":params[1]}
    resp = requests.post(url=url,data=data)
    result = resp.json()
    hot_comments = result['data']['hotComments']
    if hot_comments:
        hot_comments = [{"content":hot['content'],"timeStr":hot['timeStr'],"likedCount":hot['likedCount'],"user":hot['user']['nickname'],"avatarUrl":hot['user']['avatarUrl']} for hot in hot_comments]
    
        for hot in hot_comments:
            print(hot)
    else:
        print("该歌曲暂无热评！")
else:
    print("未查到该歌曲！")


lyric = get_lyric(song_id)
print(lyric)
